<template>
  <div>

    <BasicTable @register="registerTable">
      <template #tableTitle>
        <Button type="primary" @click="goBack">返回</Button>

      </template>
      <template #toolbar>
        <Button type="primary" @click="handleCreate"> 新增 </Button>
      </template>
      <template #bodyCell="{ column, record }">
        <template v-if="column.key === 'action'">
          <TableAction :actions="[
            {
              icon: 'clarity:note-edit-line',
              onClick: handleEdit.bind(null, record),
            },
            {
              icon: 'ant-design:delete-outlined',
              color: 'error',
              popConfirm: {
                title: '是否确认删除',
                placement: 'left',
                confirm: handleDelete.bind(null, record),
              },
            },
          ]" />
        </template>
      </template>
    </BasicTable>
    <MenuDrawer @register="registerDrawer" @success="handleSuccess" />
<!--    <MenuDrawer2 @register="registerModal" @success="handleSuccess"></MenuDrawer2>-->

  </div>
</template>
<script lang="ts" setup>
import {  onMounted } from 'vue';
import { BasicTable, useTable, TableAction } from '@/components/Table';
import { settingLineList, settingLineDelete } from '@/api/sys/approval';
import { useDrawer } from '@/components/Drawer';
import { useGo } from '@/hooks/web/usePage';
import { Button } from 'ant-design-vue';
 import { useModal} from '@/components/Modal';

import MenuDrawer from './MenuDrawer.vue';

import { columns, searchFormSchema } from './menu.data';
import { useRouter } from 'vue-router';
const router = useRouter();
const go = useGo();

const approvalSettingId = router.currentRoute.value.params.approvalSettingId;
// console.log("----approvalSettingId:", approvalSettingId);

// console.log("----approvalSettingId:", approvalSettingId);



defineOptions({ name: 'MenuManagement' });

const [registerDrawer, { openDrawer }] = useDrawer();
const [registerTable, { reload }] = useTable({
  title: '审批链路列表',
  api: settingLineList,
  columns,
  formConfig: {
    labelWidth: 120,
    schemas: searchFormSchema,
    autoSubmitOnEnter: true,
  },
  useSearchForm: true,
  showTableSetting: true,
  bordered: true,
  beforeFetch(info) {
    // console.log("----info:",info)
    info.approvalSettingId = approvalSettingId;
     return info;
  },
  actionColumn: {
    width: 120,
    title: '操作',
    dataIndex: 'action',
  },
});

onMounted(() => {

});

function goBack() {
  // 本例的效果时点击返回始终跳转到账号列表页，实际应用时可返回上一页
  router.go(-1);
}
function handleCreate() {
  openDrawer(true, {
    isUpdate: false,
    record:{
      approvalSettingId
    }
  });
}

function handleEdit(record: Recordable) {
  openDrawer(true, {
    record,
    isUpdate: true,
  });
}

function handleDelete(record: Recordable) {
  settingLineDelete(record).then(() => {
    reload();
  })
}

function handleSuccess() {
  reload();
}


</script>
